/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package coda.util;

import java.util.Arrays;
import java.util.Iterator;

/**
 *
 * @author pan
 */
public class PathUtil {
    
    public static final char SEPARATOR = System.getProperty("file.separator").charAt(0);
    public static final String HOME = System.getProperty("user.home");

    public static String join(String... args) {

        StringBuilder path = new StringBuilder();

        for (Iterator iter = Arrays.asList(args).iterator(); iter.hasNext();) {
            path.append(iter.next());
            if (iter.hasNext()) {
                if (path.length() > 0 && path.charAt(path.length() - 1) != SEPARATOR) {
                    path.append(SEPARATOR);
                }
            }
        }

        return path.toString();
    }

    public static String expand(String path) {
        if (path != null) {
            return path.replaceFirst("~", HOME);
        } else {
            return path;
        }
    }

}
